/*******************************************************************************
 * Copyright (c) 2014 Joel Thurlby.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 * 
 * Contributors:
 *     Joel Thurlby - initial API and implementation
 ******************************************************************************/
package jat.xtext.gantt.scoping

import com.google.inject.Inject
import jat.xtext.gantt.ganttText.Role
import jat.xtext.gantt.ganttText.RoleAssignment
import jat.xtext.gantt.ganttText.TaskDuration
import org.eclipse.emf.ecore.EReference
import org.eclipse.xtext.naming.IQualifiedNameConverter
import org.eclipse.xtext.scoping.IScope
import org.eclipse.xtext.scoping.Scopes
import org.eclipse.xtext.scoping.impl.AbstractDeclarativeScopeProvider

/**
 * This class contains custom scoping description.
 * 
 * see : http://www.eclipse.org/Xtext/documentation.html#scoping
 * on how and when to use it 
 *
 */
class GanttTextScopeProvider extends AbstractDeclarativeScopeProvider {
	@Inject IQualifiedNameConverter converter;

	def scope_RoleAssignment_role(RoleAssignment context, EReference ref) {
		val duration = context.eContainer as TaskDuration
		return Scopes::scopeFor(duration.taskType.roles,
			[Role input|converter.toQualifiedName(duration.taskType.name + "." + input.name)], IScope.NULLSCOPE);
	}
}
